package main

import (
	"strconv"
	"fmt"
	"os"
	"bufio"
	"io"
	"strings"
)

func main() {
	fmt.Println(
		convertToBin(5),
		convertToBin(345),
		convertToBin(565),
		convertToBin(992),
	)
	s := `akldfjas
			asdfkjaskdfas

dfasfkasd
fasdfasd
fasdfasd`

	printFileContent(strings.NewReader(s))
	printFile("studygo/abc.txt")
}
func convertToBin(n int) string { //十进制 --> 二进制
	result := ""
	for ; n>0; n /= 2 {
		lsb := n % 2
		result = strconv.Itoa(lsb) + result
	}
	return result
}

func printFile(filename string)  {
	file, err := os.Open(filename);
	if err != nil{
		panic(err)
	}
	printFileContent(file)
}

func printFileContent(reader io.Reader) {
	scanner := bufio.NewScanner(reader)
	for scanner.Scan() { //没有初始条件，没有递增条件，只有结束条件
		fmt.Println(scanner.Text())
	}
}

func forever()  { //死循环
	for {
		fmt.Println("abc")
	}
}